$(function(){
	var res_user = false;
	var res_phone = false;
	var res_email = false;
	//姓名验证
	$("#user").focus(function(){
		$("#user_check").html("请输入真实姓名"); 
		$("#user_check").css("color","#666");
	});
	$("#user").bind("focusout",function(){
		var name=$.trim($(this).val());
		var pattern= /[a-zA-Z]{1,20}|[\u4e00-\u9fa5]{1,10}/;
		if(name==""){
			$("#user_check").html("姓名不能为空");
			$("#user_check").css("color","#ff0000");
			return res_user=false;
		}else if(!pattern.test(name)){
			$("#user_check").html("请输入正确的名字");
			$("#user_check").css("color","#ff0000");
			return res_user=false;
		}else{
			return res_user=true;
		}
	});
	//电话验证
	$("#phone").focus(function(){
		$("#phone_check").html("为方便联系您，请输入正确的常用电话号码"); 
		$("#phone_check").css("color","#666");
	});
	$("#phone").bind("focusout",function(){
		var phone=$.trim($(this).val());
		var pattern= /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
		if(phone==""){
			$("#phone_check").html("电话不能为空");
			$("#phone_check").css("color","#ff0000");
			return res_phone=false;
		}else if(!pattern.test(phone)){
			$("#phone_check").html("请输入正确电话号码");
			$("#phone_check").css("color","#ff0000");
			return res_phone=false;
		}else{
			return res_phone=true;
		}
	});
	//邮箱验证
	$("#email").focus(function(){
		$("#email_check").html("为方便联系您，请输入正确的常用邮箱"); 
		$("#email_check").css("color","#666");
	});
	var res_email=true;
	$("#email").bind("focusout",function(){
		var email=$.trim($(this).val());
		var pattern=/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		if(email==""){
			$("#email_check").html("邮箱不能为空");
			$("#email_check").css("color","#ff0000");
			return res_email=false;
		}else if(!pattern.test(email)){
			$("#email_check").html("邮箱格式错误");
			$("#email_check").css("color","#ff0000");
			return res_email=false;
		}else{
			return res_email=true;
		}
	});
	
	$("#sub").click(function(){
		if ($("#yzm").val()=="") {
			alert("请输入验证码")
		}else if(res_user==false||res_phone==false||res_email==false){
    		alert("请输入正确的信息");
		}else{
			$("#mainForm").submit();
		}
	});
	
});
